package com.example.demo3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;

import com.example.demo3.adapter.CustomAdapter;
import com.example.demo3.bean.Student;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_listview);

        ListView listView = findViewById(R.id.list);

        CustomAdapter adapter = new CustomAdapter(getData(), this);

        listView.setAdapter(adapter);
    }

    /**
     * 初始话数据
     *
     * @return
     */
    private List<Student> getData() {
        List<Student> students = new ArrayList<>();
        Student xiaoming = new Student("小明", 11);
        Student xiaohong = new Student("小红", 11);
        Student xiaoli = new Student("小李", 11);
        Student xiaowang = new Student("小王", 11);

        //添加数据到集合
        students.add(xiaoming);
        students.add(xiaohong);
        students.add(xiaoli);
        students.add(xiaowang);

        return students;
    }
}